# #随机采样
# import random
# str = "qazwsx"
# list =[ 1,2,4,5,6 ]
# n_samples = 2 #想要抽选的数量
# print (random.sample( list, n_samples ))
# print (random.sample( str, n_samples ))
#
# #使用random.sampLe()函教，可以从一个序列中选择n_samples个随机且独立的元素。


# print('\n')
# def combine(m,n) :
# #在函数体里构建一个fac函数来求x的阶乘，进而用m!/(n!-(m-n)!求组合数C(m,n)，其中m≥n举组合数公式,),
#     def fac(x) :
#         if x<=1:
#             return 1
#         s=1
#         for i in range(1,x+1):
#             s=s*i
#         return s
#     return fac(m) / ( fac(n)*fac(m-n))
# print("C(5,3)=" ,combine(5,3))
# print("C(10,2)=",combine(10,2))


#从N个里取C个的排列组合
def combination(n,c,com=1,limit=0,per=[]): #com表示排列还是组合
    for pos in range(limit,n): # 0——n遍历
        t = per + [pos] #两个列表可进行元素相加
        if len(set(t)) == len(t):
            if len(t) == c:
                yield [pos,]
            else:
                for result in combination(n,c,com,com*pos, per + [pos,]):
                    yield [pos,] + result
print("排列：")
for res in combination(3,3,0):
    print(res)
print("组合：")
for res in combination(3,3):
    print(res)


# print('\n')
# #调用模块itertools
# import itertools
# d={'LPL':1 , 'LCK':2, 'EU':3}
# '''将Node_txt文本中的所有内容输出来'''
# with open("Node_txt",'r+',encoding='utf_8') as file:
#     lst=file.readlines()
#     for i in lst:
#         print(i,end='')
# print('\n')
# print(list(itertools.combinations(range(5),3 ) ) )
# list1=list( itertools.combinations(d.values() ,2) )
# list2=list( itertools.combinations(d.keys() ,2) )
# list3=list(itertools.combinations(d.items() ,2))
# print(list1)
# print(list2)
# print(list3)
#
# s=[1,2,3]
# list2=list(itertools.permutations(s,3) )
# print(list2)
